package cn.itsource.org.controller;


import cn.itsource.org.domain.Employee;
import cn.itsource.org.service.IEmployeeService;
import cn.itsource.util.AjaxResult;
import cn.itsource.util.Constant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Employee")
@Api("这个增删改查,和登录的接口")
public class EmployeeController {

    /**
     * 注入service层
     */
    @Autowired
    private IEmployeeService employeeService;

      


    @GetMapping("/empl")
    @ApiOperation(  value = "默认启动",notes = "查询所有")
    public List<Employee> fainAll(){
        return employeeService.fainAll();
    }

    @DeleteMapping("{id}")
    public AjaxResult Delete(@PathVariable("id") Long id){

        try {
            employeeService.delete(id);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.returnFailure("删除异常,请找管理员");
        }
    }
    @PostMapping("/save")
    public AjaxResult saveOrupdate(@RequestBody Employee employee){

        try {
            if (employee.getId() == null){
                employeeService.save(employee);
            }else{
                employeeService.update(employee);
            }
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.returnFailure(Constant.SYSTEM_EXCEPTION,"系统异常");
        }

    }











}
